<?php 
require_once '../include.php';

$keywords=$_REQUEST['keywords']?$_REQUEST['keywords']:null;
$where=$keywords?"where concat_ws(' ',a.name,a.name2,a.region,a.description) like '%{$keywords}%'":null;

// $sql="select a.*,b.prov_name 
// from public.user a 
// join public.region b 
// on a.area_code=b.prov_code
// {$where}
// ";
//order by a.name desc,b.prov_code asc  limit {$pageSize}
// var_dump($sql);

//$sql="select * from sde.lakes a {$where}";
$sql="select * from public.tb01 a {$where}";

//$GLOBALS["DB_HOST12345"] = "gis25.jlu3s.com";
//echo $GLOBALS["DB_HOST12345"];
// var_dump($GLOBALS["DB_HOST12345"]);
//var_dump($DB_HOST);
//var_dump($DB_NAME);

//$PG = new pgsql("01.jlu3s.com", "5432", "mygdb_t1", "sde", "52GIS915");  

$PG = new pgsql($DB_HOST, $DB_PORT, $DB_NAME, $DB_USERNAME, $DB_PASSWORD);  
$PG->connect(); 
if(!$PG){ 
	$db_error = "无法连接到PostGreSQL数据库！"; echo $db_error; 
}else{  
    $rows = $PG->fetchAll($sql);
	//var_dump($rows);
	//if(is_null($rows)){ echo "未查到相关数据";}else{ foreach($rows as $row):echo $row['prov_name'];endforeach;}
	//echo $rows;
	echo json_encode($rows);
}


?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>-.-</title>
<style>

/* 操作栏*/
.caozuolan {
	display:flex;
	flex-direction: row;
	justify-content: flex-end;
	align-items: center;
	height:50px;
}
.search_user{
	/* background-color: #008000; */
	width:400px;

	display:flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: center;
}
.searchword{
	width:240px;
}
.btn_search_click{
	cursor:pointer;
	margin-left:20px;
}

.btn2 {
	padding: 2px 2px;
	color:white; 
	background-color: #600080; 
	margin: 0 5px;
	font-family: "微软雅黑"; 
	font-size: 12px;
	cursor:pointer;
	height:32px;
}

.add_user{
	/* background-color: #ff8040; */
	width:100px;
	margin-right:50px;
	margin-left:50px;
}

/*表格*/
.table{border-collapse: collapse; width: 100%; font-size: 12px;}
.table th{background-color: #E8E8E8;}
.table th,
.table td{border: solid 1px #ccc; padding: 3px;}
.label,.check{vertical-align: middle;}
.check{margin-right: 4px;}
.btn{padding: 2px 2px;color:white; background-color: #008000; margin: 0 5px;font-family: "微软雅黑"; font-size: 12px;cursor:pointer; }
.btn:hover{background-color: #ff8040;}
</style>
</head>

<body>
<h2>用户管理</h2>
<div class="details">
					<div class="caozuolan">
                        
                        <div class="search_user">                            
                            <div class="text">
                                <span>搜索：</span>
                                <input type="text" value="" class="searchword"  id="search" onkeypress="SearchLakes()" placeholder="名称、描述、所属区域等" >
                            </div>
							<div class="btn_search_click"><input type="button" value="点击搜索" class="btn2" onclick="SearchLakes()"></div>
                         </div>

						 <div class="add_user">
                            <input type="button" value="添&nbsp;加&nbsp;新&nbsp;要&nbsp;素"  class="btn2" onclick="AddLake()">
                        </div>
                    </div>
                    <!--表格-->
                    <table class="table" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr >
                                <th>编号</th>
                                <th>名称</th>                               
                                <th>名称（英文）</th>
                                <th>所在区域</th>
                                <th>描述</th>                                
                                <th>图片</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
							<?php if(is_null($rows)){ echo "未查到相关数据";}else{ foreach($rows as $key=>$row):?>
                            <tr>
                                <!--各行循环出来-->								
                                <td><input type="checkbox" id="c" class="check" value=<?php echo $row['objectid'];?>><label for="c1" class="label"><?php echo $key+1;?></label></td>
                                <td><?php echo $row['name'];?></td>                               
                                <td><?php echo $row['name2'];?></td>
                                <td><?php echo $row['region'];?></td>
                                <td><?php echo $row['description'];?></td>
                                <td><?php echo $row['picture_path'];?></td> 
                                <td align="center">                                    
                                    <input type="button" value="修改" class="btn" onclick="EditUser(<?php echo $row['uid'];?>)" style="cursor:pointer" />
									<input type="button" value="删除" class="btn" onclick="DeleteUser('<?php echo $row['uid'];?>','<?php echo $row['name'];?>')" style="cursor:pointer" />                                   
                                </td>								
                            </tr>
							<?php endforeach;}?>

                        </tbody>
                    </table>
                </div>
<script type="text/javascript">

    function EditUser(uid){
		window.location="EditUser.php?uid="+uid;
	}

	function DeleteUser(uid,name){
		if(window.confirm("您确认要删除【 " + name + " 】用户吗？")){
			window.location="doDeleteUser.php?uid="+uid;
		}
	}

    /*点击搜索按钮时执行的方法 */
	function SearchLakes(){
		if(event.keyCode==13){
			var val=document.getElementById("search").value;
			window.location="xxDataList.php?keywords="+val;
		}else{
			var val=document.getElementById("search").value;
			window.location="xxDataList.php?keywords="+val;
		}
	}

	function AddLake(){
		window.location="AddLake.php";
	}

</script>
</body>
</html>